import { TypeOrmModuleOptions } from '@nestjs/typeorm';
import { ConfigService } from '@nestjs/config';

export const databaseConfig = async (configService: ConfigService): Promise<TypeOrmModuleOptions> => {
// console.log(configService.get('DB_HOST'));
// console.log(configService.get('DB_PORT'));
// console.log(configService.get('DB_USERNAME'));
// console.log(configService.get('DB_PASSWORD'));
// console.log(configService.get('DB_DATABASE'));
// console.log(configService.get('DB_ENTITIES'));
// console.log(configService.get('DB_SYNCHRONIZE'));
console.log(configService.get<string>('DB_SYNCHRONIZE') === 'true',"=========-------======++++++++++");

  return {
    type: configService.get<string>('DB_TYPE') as 'mysql',
    host: configService.get<string>('DB_HOST'),
    port: +configService.get<number>('DB_PORT'),
    username: configService.get<string>('DB_USERNAME'),
    password: configService.get<string>('DB_PASSWORD'),
    database: configService.get<string>('DB_DATABASE'),
    entities: [configService.get<string>('DB_ENTITIES')],
    synchronize: configService.get<string>('DB_SYNCHRONIZE') === 'true',
    // logging: true,
    autoLoadEntities: true,
  }
};
